package com.library.admin.form;

import com.library.admin.listener.HideFormListener;
import com.library.admin.listener.LoginSubmitListener;
import com.vaadin.ui.Button;
import com.vaadin.ui.Form;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;

public class LoginForm extends Form {
	private static final long serialVersionUID = 7962557625637247246L;
	
	private TextField loginTextBox;
	private PasswordField passwordTextBox;
	private Button submitButton;
	private Button closeButton;
	
	public LoginForm() {
		init();
	}

	private void init() {
		setWidth("100%");
		
		loginTextBox = new TextField("Login");
		passwordTextBox = new PasswordField("Mot de passe");
		submitButton = new Button("OK");
		closeButton = new Button("Fermer");
		
		submitButton.addListener(new LoginSubmitListener(this));
		closeButton.addListener(new HideFormListener(this));
		
		addField("loginTextBox", loginTextBox);
		addField("passwordTextBox", passwordTextBox);
		addField("submitButton", submitButton);
		addField("closeButton", closeButton);
		
		getField("loginTextBox").setRequired(true);
		getField("loginTextBox").setRequiredError("Le champ \"Login\" est obligatoire");
		getField("passwordTextBox").setRequired(true);
		getField("passwordTextBox").setRequiredError("Le champ \"Mot de passe\" est obligatoire");
	}

	public TextField getLoginTextField() {
		return loginTextBox;
	}

	public PasswordField getPasswordTextField() {
		return passwordTextBox;
	}

	public Button getSubmitButton() {
		return submitButton;
	}

	public Button getCloseButton() {
		return closeButton;
	}
}
